﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.UserGroup
{
    public class UserGroupPresenter : Presenter<IUserGroupView>
    {
        public UserGroupPresenter(IUserGroupView view)
            : base(view)
        {
        }

        public void Display(string userGroupId)
        {
            if (userGroupId == null) return;

            var userGroup = Model.GetUserGroup(userGroupId);

            View.UserGroupID = userGroup.UserGroupID;
            View.UserGroupName = userGroup.UserGroupName;
            View.Image = userGroup.Image;
            View.RestaurantID = userGroup.RestaurantID;
            View.CreateBy = userGroup.CreateBy;
            View.CreateDate = userGroup.CreateDate;
            View.ModifiedBy = userGroup.ModifiedBy;
            View.ModifiedDate = userGroup.ModifiedDate;
            View.Description = userGroup.Description;
            View.IsActive = userGroup.IsActive;
        }

        public int Save()
        {
            var userGroup = new UserGroupModel
            {
                UserGroupID = View.UserGroupID,
                UserGroupName = View.UserGroupName,
                Image = View.Image,
                RestaurantID = View.RestaurantID,
                CreateBy = View.CreateBy,
                CreateDate = View.CreateDate,
                ModifiedBy = View.ModifiedBy,
                ModifiedDate = View.ModifiedDate,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (userGroup.UserGroupID == null)
                return Model.AddUserGroup(userGroup);
            else
                return Model.UpdateUserGroup(userGroup);
        }

        public int Delete(string userGroupId)
        {
            return Model.DeleteUserGroup(userGroupId);
        }
    }
}
